package Client;


import javax.swing.*;
import java.awt.*;
import java.net.Socket;


public class LoginUI extends JFrame {

    static JTextField UidText;//用户输入的登录账号

    static JPasswordField UpswText;//用户输入的登陆密码

    JButton bLogin, bCancel, bSignup;//界面的按钮
    /**
     * 退出按钮
     */
    JButton bExit;
    /**
     * 最小化按钮
     */
    JButton bMin;

    private LoginUI() {
        setTitle("用户登录");
        setIconImage(new ImageIcon("src/image/title.png").getImage());//左上角图标
        setSize(437, 340);
        setLocationRelativeTo(null);//将容器显示在屏幕中央
        setUndecorated(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);//关闭窗口
        LoginUISet();//调用组件布局界面方法
        setLoginActionListener(new LoginActionListener(this));//设置监听器对象
        setVisible(true);

    }

    public static void main(String[] args) {
        new LoginUI();
    }

    private void LoginUISet() {//组件布局方法


        setLayout(null);

        Font font1 = new Font("楷体", Font.BOLD, 20);

        //设置各个组件的位置，字体

        bExit = new JButton("✕");
        bExit.setBorder(null);
        bExit.setOpaque(false);
        bExit.setBackground(Color.CYAN);
        bExit.setBounds(393, 5, 40, 30);
        add(bExit);

        bMin = new JButton("—");
        bMin.setBorder(null);
        bMin.setOpaque(false);
        bMin.setBackground(Color.white);
        bMin.setBounds(353, 5, 40, 30);
        add(bMin);

        JLabel lUid = new JLabel("账号:");//设置id的文字
        lUid.setBounds(85, 130, 50, 50);//设置文在所在的位置
        lUid.setFont(font1);//设置字体
        UidText = new JTextField(30);//设置输入框
        UidText.setOpaque(false);
        UidText.setBounds(new Rectangle(145, 140, 150, 30));//设置位置
        UidText.setFont(font1);//设置字体
        UidText.setEditable(true);
        UidText.requestFocus();

        JLabel lUpsw = new JLabel("密码:");
        lUpsw.setBounds(85, 190, 50, 50);
        lUpsw.setFont(font1);
        UpswText = new JPasswordField(30);//设置输入框
        UpswText.setOpaque(false);
        UpswText.setBounds(new Rectangle(145, 200, 150, 30));//设置位置
        UpswText.setFont(font1);//设置字体
        UpswText.setEditable(true);

        Font font2 = new Font("楷体", Font.BOLD, 15);

        bLogin = new JButton("登录");
        bLogin.setBackground(Color.CYAN);
        bLogin.setBounds(new Rectangle(110, 255, 70, 30));
        bLogin.setFont(font2);
        getRootPane().setDefaultButton(bLogin);

        bCancel = new JButton("取消");
        bCancel.setBackground(Color.CYAN);
        bCancel.setBounds(new Rectangle(190, 255, 70, 30));
        bCancel.setFont(font2);

        bSignup = new JButton("注册");
        bSignup.setBackground(Color.cyan);
        bSignup.setBounds(new Rectangle(270, 255, 70, 30));
        bSignup.setFont(font2);

        //将各个组将添加到容器里面
        add(lUid);
        add(UidText);

        add(lUpsw);
        add(UpswText);

        add(bLogin);
        add(bCancel);
        add(bSignup);


        Background bg = new Background();
        bg.setImage(this.getToolkit().getImage("src/image/loginbg.png"));
        bg.setBounds(0, 0, 437, 340);
        add(bg);
        repaint();


    }

    private void setLoginActionListener(LoginActionListener la) {
        bExit.addActionListener(la);
        bMin.addActionListener(la);
        bLogin.addActionListener(la);
        bCancel.addActionListener(la);
        bSignup.addActionListener(la);
    }

}

